<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/blog/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/blog/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/blog/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Java面试,">










<meta name="description" content="本文学习《剑指Java面试-Offer直通车》第十章，主要内容为: Java常用类库与技巧视频课程地址：https://coding.imooc.com/class/303.html项目代码地址：https://gitee.com/aiolos123/java_basic">
<meta name="keywords" content="Java面试">
<meta property="og:type" content="article">
<meta property="og:title" content="【四】剑指Java面试Offer直通车-Java常用类库与技巧">
<meta property="og:url" content="https://aiolos123.gitee.io/blog/2019/12/22/java-interview-offer-4/index.html">
<meta property="og:site_name" content="Aiolos">
<meta property="og:description" content="本文学习《剑指Java面试-Offer直通车》第十章，主要内容为: Java常用类库与技巧视频课程地址：https://coding.imooc.com/class/303.html项目代码地址：https://gitee.com/aiolos123/java_basic">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20200111063330576.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20200111065806525.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20200111070514915.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20200111071753295.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20200111072143787.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20200111072709677.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20200111072849782.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20200111073002930.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20200111073204140.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20200113111446604.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20200113112240362.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20200113113149537.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20200113114225825.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20200113114334063.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20200113115243449.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20200113124003016.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20200113124027157.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20200113124027157.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20200113134901110.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20200113135437133.jpg">
<meta property="og:updated_time" content="2020-01-13T05:59:50.323Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="【四】剑指Java面试Offer直通车-Java常用类库与技巧">
<meta name="twitter:description" content="本文学习《剑指Java面试-Offer直通车》第十章，主要内容为: Java常用类库与技巧视频课程地址：https://coding.imooc.com/class/303.html项目代码地址：https://gitee.com/aiolos123/java_basic">
<meta name="twitter:image" content="https://aiolos123.gitee.io/blog/images/20200111063330576.jpg">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/blog/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://aiolos123.gitee.io/blog/2019/12/22/java-interview-offer-4/">





  <title>【四】剑指Java面试Offer直通车-Java常用类库与技巧 | Aiolos</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blog/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Aiolos</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">记录我的成长点滴</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/blog/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/blog/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/blog/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br>
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off" placeholder="搜索..." spellcheck="false" type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://aiolos123.gitee.io/blog/blog/2019/12/22/java-interview-offer-4/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="aiolos">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Aiolos">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">【四】剑指Java面试Offer直通车-Java常用类库与技巧</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-12-22T05:59:13+08:00">
                2019-12-22
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/Java基础/" itemprop="url" rel="index">
                    <span itemprop="name">Java基础</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>本文学习《剑指Java面试-Offer直通车》第十章，主要内容为: Java常用类库与技巧<br>视频课程地址：<a href="https://coding.imooc.com/class/303.html" target="_blank" rel="noopener">https://coding.imooc.com/class/303.html</a><br>项目代码地址：<a href="https://gitee.com/aiolos123/java_basic" target="_blank" rel="noopener">https://gitee.com/aiolos123/java_basic</a></p>
<a id="more"></a>

<h2 id="Java异常及常用工具类体系"><a href="#Java异常及常用工具类体系" class="headerlink" title="Java异常及常用工具类体系"></a>Java异常及常用工具类体系</h2><ol>
<li><p>Java异常处理机制主要回答了三个问题</p>
<blockquote>
<p>What: 异常类型回到了什么被抛出<br>Where: 异常堆栈跟踪回答了在哪抛出<br>Why: 异常信息回答了为什么被抛出</p>
</blockquote>
</li>
<li><p>Java异常体系</p>
</li>
</ol>
<p>Java异常体系如下图：<br><img src="/blog/images/20200111063330576.jpg" alt="Java异常体系"></p>
<ol start="3">
<li>Error和Exception的区别<blockquote>
<p>回答角度：从概念角度解析Java的异常处理机制</p>
</blockquote>
</li>
</ol>
<table>
<thead>
<tr>
<th>区别</th>
<th>Error</th>
<th>Exception</th>
</tr>
</thead>
<tbody><tr>
<td>概念</td>
<td>程序无法处理的系统错误，编译器不做检查。</td>
<td>程序可以处理的异常</td>
</tr>
<tr>
<td>举例</td>
<td>一般指与JVM相关的问题，如系统奔溃、JVM错误、内存空间不足(OOM)、方法栈溢出(Stackflow Error)、NoClassDefFoundError</td>
<td></td>
</tr>
<tr>
<td>特点</td>
<td>这类错误导致的程序中断，仅靠程序无法恢复和预防。遇到这类错误，建议终止程序</td>
<td>捕获后程序可能恢复。遇到这类错误，尽可能捕获使程序恢复运行</td>
</tr>
<tr>
<td>本质区别</td>
<td>Error是程序无法处理的错误</td>
<td>Exception是程序可以处理的异常</td>
</tr>
</tbody></table>
<ol start="4">
<li>Exception的体系</li>
</ol>
<table>
<thead>
<tr>
<th>区别</th>
<th>RuntimeException</th>
<th>非RuntimeException</th>
</tr>
</thead>
<tbody><tr>
<td>概念</td>
<td>运行时Exception，是不可预知的异常、程序开发人员应当自行避免</td>
<td>RuntimeException以外的异常，可预知的，编译器能校验、且必须处理的异常。如不处理，程序无法编译通过</td>
</tr>
<tr>
<td>举例</td>
<td>如数组越界、空指针、ClassCaseException、IllegalArgumentException、NumberFormatException</td>
<td>如IO异常、SQL异常、ClassNotFoundException</td>
</tr>
<tr>
<td>责任角度</td>
<td>Error属于JVM需要负担的责任；RuntimeException是程序开发人员应该负担的责任</td>
<td>非RuntimeException(Checked Exception)是编译器应该负担的责任</td>
</tr>
</tbody></table>
<ol start="5">
<li>常见Error及Exception<br><img src="/blog/images/20200111065806525.jpg" alt="常见Error及Exception"></li>
</ol>
<h2 id="Java异常处理机制"><a href="#Java异常处理机制" class="headerlink" title="Java异常处理机制"></a>Java异常处理机制</h2><p>Java异常处理机制主要经过如下2个步骤：</p>
<ol>
<li>抛出异常： 创建异常对象，交由运行时系统处理</li>
<li>捕获异常： 寻找合适的异常处理器处理异常，否则终止运行</li>
</ol>
<p>Java异常处理机制如下图：<br><img src="/blog/images/20200111070514915.jpg" alt="Java异常处理机制"></p>
<p><strong>注意：Finally语句块会在Catch中的return语句之前执行</strong></p>
<ol start="3">
<li><p>Java异常处理原则</p>
<blockquote>
<p>具体明确：抛出的异常应能通过异常类名和Message准确说明异常的类型和产生异常的原因；<br>提早抛出： 应尽可能早的发现并抛出异常，便于精准定位问题<br>延迟捕获： 异常的捕获和处理尽可能延迟，让掌握更多信息的作用域来处理异常。<br>持久化异常：尽可能将异常详细信息持久化到日志中</p>
</blockquote>
</li>
<li><p>设计高效主流的异常处理框架</p>
<blockquote>
<p>在用户看来，应用系统发生的所有异常都是应用系统内部的异常；</p>
</blockquote>
</li>
</ol>
<p>a. 设计一个通用的、继承自RuntimeException的异常AppException来统一处理系统运行过程中的所有异常<br>b. 其他异常都统一转译为上述的异常AppException<br>c. 如何转译：在catch之后，抛出AppException异常的具体子类，并提供足以定位的信息<br>d. 由前端接收AppException做统一处理</p>
<p>高效主流的异常处理框架如下图：<br><img src="/blog/images/20200111071753295.jpg" alt="高效主流的异常处理框架"></p>
<ol start="5">
<li>try-catch的性能问题<blockquote>
<p>Java异常处理消耗性能的地方有2处:<br>a. try-catch块会影响JVM的优化<br>b. 异常对象实例需要保存栈快照等信息，开销较大</p>
</blockquote>
</li>
</ol>
<p>结论：使用try-catch仅捕获可能出现异常的必要代码段；不要使用try-catch控制程序的执行流程，因为它的效率远不如if、else、switch这些控制语句。如下图：</p>
<p><img src="/blog/images/20200111072143787.jpg" alt="try-catch的性能问题"></p>
<h2 id="Java集合框架体系"><a href="#Java集合框架体系" class="headerlink" title="Java集合框架体系"></a>Java集合框架体系</h2><ol>
<li><p>工作中消失而面试却长存的算法和数据结构————优秀的算法和数据结构被封装到了Java的集合框架之中</p>
</li>
<li><p>面试常考的算法和数据结构<br><img src="/blog/images/20200111072709677.jpg" alt="面试常考的算法和数据结构"><br><img src="/blog/images/20200111072849782.jpg" alt="面试常考的算法和数据结构"></p>
</li>
<li><p>Java集合框架体系<br><img src="/blog/images/20200111073002930.jpg" alt="Java集合框架体系"></p>
</li>
<li><p>集合之List和Set<br><img src="/blog/images/20200111073204140.jpg" alt="集合之List和Set"></p>
</li>
</ol>
<h2 id="HashMap"><a href="#HashMap" class="headerlink" title="HashMap"></a>HashMap</h2><blockquote>
<p>Map: 键值对；键唯一；</p>
</blockquote>
<ol>
<li><p>Map的整体结构如下图：<br><img src="/blog/images/20200113111446604.jpg" alt="Map的整体结构"></p>
</li>
<li><p>HashTable、HashMap、ConcurrentHashMap的区别</p>
</li>
</ol>
<table>
<thead>
<tr>
<th>区别</th>
<th>HashMap</th>
<th>HashTable</th>
<th>ConcurrentHashMap</th>
</tr>
</thead>
<tbody><tr>
<td>底层实现</td>
<td>(Java8之前)： 数组+链表；(Java8及之后)：数组+链表+红黑树</td>
<td>数组+链表</td>
<td>数组+链表+红黑树</td>
</tr>
<tr>
<td>特点</td>
<td>成员变量的数据结构、树化阈值；延迟创建；哈希算法；2倍扩容；性能</td>
<td></td>
<td></td>
</tr>
<tr>
<td>图示</td>
<td><img src="/blog/images/20200113112240362.jpg" alt="Map的整体结构"></td>
<td></td>
<td></td>
</tr>
<tr>
<td>线程安全性</td>
<td>线程不安全</td>
<td>线程安全：锁住整个对象</td>
<td>线程安全：CAS+同步锁(将锁细粒度化到table的每个元素)</td>
</tr>
</tbody></table>
<blockquote>
<p>HashMap的key、value均可为null，而其他两个类不支持</p>
</blockquote>
<ol start="3">
<li><p>HashMap的源码分析如下：<br><img src="/blog/images/20200113113149537.jpg" alt="HashMap的源码分析"><br><img src="/blog/images/20200113114225825.jpg" alt="HashMap的源码分析"><br><img src="/blog/images/20200113114334063.jpg" alt="HashMap的源码分析"></p>
</li>
<li><p>HashMap： 如何有效减少碰撞？</p>
<blockquote>
<p>扰动函数: 促使元素位置分布均匀，减少碰撞几率。<br>使用final对象，并采用合适的equals()和hashCode()方法</p>
</blockquote>
</li>
</ol>
<p>使用String、Integer对象作为key是非常好的！！！</p>
<ol start="5">
<li><p>HashMap扩容问题</p>
<blockquote>
<p>多线程环境下，调整大小会存在条件竞争，容易造成死锁<br>rshashing是一个比较耗时的过程</p>
</blockquote>
</li>
<li><p>如何优化HashTable</p>
<blockquote>
<p>通过锁细粒度化，将整个锁拆解成多个锁进行优化</p>
</blockquote>
</li>
</ol>
<h2 id="ConcurrentHashMap"><a href="#ConcurrentHashMap" class="headerlink" title="ConcurrentHashMap"></a>ConcurrentHashMap</h2><ol>
<li><p>早期的ConcurrentHashMap实现原理<br><img src="/blog/images/20200113115243449.jpg" alt="早期的ConcurrentHashMap实现原理"></p>
</li>
<li><p>Java8及以后的ConcurrentHashMap实现原理<br><img src="/blog/images/20200113124003016.jpg" alt="Java8及以后的ConcurrentHashMap实现原理"></p>
</li>
<li><p>put()方法的逻辑<br><img src="/blog/images/20200113124027157.jpg" alt="ConcurrentHashMap的put()方法的逻辑"></p>
</li>
<li><p>总结</p>
<blockquote>
<p>比起Segment，锁拆分的更细。只要Hash不冲突，就不会发生并发获得锁的情况<br>首先是要无锁操作CAS插入头结点，失败则循环重试<br>若头结点已存在，则尝试获取头结点的同步锁，再进行操作。</p>
</blockquote>
</li>
</ol>
<h2 id="JUC知识点梳理"><a href="#JUC知识点梳理" class="headerlink" title="JUC知识点梳理"></a>JUC知识点梳理</h2><p><strong>10-7 视频粗看</strong></p>
<blockquote>
<p>java.util.oncurrent: 提供了并发编程的解决方案</p>
</blockquote>
<ol>
<li><p>JUC中的两大核心：</p>
<blockquote>
<p>CAS：是java.util.concurrent.atomic包的基础<br>AQS：是java.util.concurrent.locks包以及一些常用类比如Semophore、ReentrantLock等类的基础</p>
</blockquote>
</li>
<li><p>JUC包的分类</p>
<blockquote>
<p>线程执行器executor；锁locks；原子变量类atomic；并发工具类tools；并发集合collections</p>
</blockquote>
</li>
</ol>
<h2 id="JavaIO机制"><a href="#JavaIO机制" class="headerlink" title="JavaIO机制"></a>JavaIO机制</h2><p><strong>10-8 视频粗看</strong></p>
<ol>
<li>BIO、NIO、AIO的区别</li>
</ol>
<table>
<thead>
<tr>
<th>区别</th>
<th>BIO</th>
<th>NIO</th>
<th>AIO</th>
</tr>
</thead>
<tbody><tr>
<td>定义</td>
<td>Block-IO: 如InputStream和OutputStream，Reader和Writer</td>
<td>NonBlock-IO：构建多路复用的、同步非阻塞的IO操作</td>
<td>AsynchronousIO：基于事件和回调机制</td>
</tr>
<tr>
<td>特点</td>
<td>基于流模型实现；代码简单</td>
<td>程序需要不断主动询问内核；由Channel、Buffer、Selector三大核心组件构成</td>
<td></td>
</tr>
<tr>
<td>交互方式</td>
<td>同步阻塞</td>
<td>同步非阻塞</td>
<td>异步非阻塞</td>
</tr>
<tr>
<td>线程数(server:client)</td>
<td>1:1</td>
<td>1:N</td>
<td>0:N</td>
</tr>
<tr>
<td>吞吐量</td>
<td>低</td>
<td>高</td>
<td>高</td>
</tr>
<tr>
<td>执行过程的图示</td>
<td><img src="/blog/images/20200113124027157.jpg" alt="执行过程"></td>
<td><img src="/blog/images/20200113134901110.jpg" alt="执行过程"></td>
<td><img src="/blog/images/20200113135437133.jpg" alt="执行过程"></td>
</tr>
</tbody></table>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/blog/tags/Java面试/" rel="tag"># Java面试</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/blog/2019/12/22/hadoop3.0-step-by-step-1/" rel="next" title="【一】快速入门Hadoop3.0大数据处理——Hadoop3.0整体概述">
                <i class="fa fa-chevron-left"></i> 【一】快速入门Hadoop3.0大数据处理——Hadoop3.0整体概述
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/blog/2019/12/22/machine-learning-classical-algorithm-3/" rel="prev" title="【三】Python3入门机器学习经典算法与应用——最基础的分类算法-kNN近邻算法">
                【三】Python3入门机器学习经典算法与应用——最基础的分类算法-kNN近邻算法 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">aiolos</p>
              <p class="site-description motion-element" itemprop="description">Java Spring Hadoop 机器学习</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/blog/archives/">
              
                  <span class="site-state-item-count">126</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/blog/categories/index.html">
                  <span class="site-state-item-count">16</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/blog/tags/index.html">
                  <span class="site-state-item-count">33</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#Java异常及常用工具类体系"><span class="nav-number">1.</span> <span class="nav-text">Java异常及常用工具类体系</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Java异常处理机制"><span class="nav-number">2.</span> <span class="nav-text">Java异常处理机制</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Java集合框架体系"><span class="nav-number">3.</span> <span class="nav-text">Java集合框架体系</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#HashMap"><span class="nav-number">4.</span> <span class="nav-text">HashMap</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#ConcurrentHashMap"><span class="nav-number">5.</span> <span class="nav-text">ConcurrentHashMap</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#JUC知识点梳理"><span class="nav-number">6.</span> <span class="nav-text">JUC知识点梳理</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#JavaIO机制"><span class="nav-number">7.</span> <span class="nav-text">JavaIO机制</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">aiolos</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/blog/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/blog/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/blog/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/blog/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/blog/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/blog/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/blog/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/blog/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/blog/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  

  
  

  

  

  

</body>
</html>
